//
//  AppDelegate+AppBasicIformation.m
//  HappilyLoan
//
//  Created by 纵情向前 on 2017/4/14.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "AppDelegate+AppBasicIformation.h"
#import "ZFHeader.h"
#import "upLoadAppApiRequest.h"
#import "ZFHttpTool.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreLocation/CoreLocation.h>

@import MapKit;
@import CoreLocation;
@interface AppBasicIformation: NSObject <CLLocationManagerDelegate> //协议
@property(nonatomic) CLLocationManager *locationManager;
@end
@implementation AppDelegate (AppBasicIformation)


//CLLocationManagerDelegate>
- (void)uploadOpenAppApiMessage:(NSString *)locationStr{
//    NSLog(@"HUAGHDADJHDBJHDBJDJDBHUD%@",locationStr);
    NSArray *subviews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"]subviews];
    NSNumber *dataNetworkItemView = nil;
    NSString *networkStr = [[NSString alloc] init];
    for (id subview in subviews) {
        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
            dataNetworkItemView = subview;
            break;
        }
    }
    
    switch ([[dataNetworkItemView valueForKey:@"dataNetworkType"]integerValue]) {
        case 0:
            NSLog(@"No wifi or cellular");
            networkStr = @"无网络连接";
            break;
            
        case 1:
            NSLog(@"2G");
            networkStr = @"2G";
            break;
            
        case 2:
            NSLog(@"3G");
            networkStr = @"3G";
            break;
            
        case 3:
            NSLog(@"4G");
            networkStr = @"4G";
            break;
            
        case 4:
            NSLog(@"LTE");
            networkStr = @"LTE";
            break;
            
        case 5:
            NSLog(@"Wifi");
            networkStr = @"Wifi";
            break;
            
            
        default:
            break;
    }
//    NSLog(@"当前网络类型：%@",networkStr);
    //手机型号
    NSString* phoneModel = [[UIDevice currentDevice] model];
//    NSLog(@"手机型号: %@",phoneModel );
    //手机系统版本
    NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
//    NSLog(@"手机系统版本: %@", phoneVersion);
    
    NSDictionary *upLoadApiInfoDic;
    if (([ZFPulicAPI getUserid])) {
        upLoadApiInfoDic = @{@"user_id":[ZFPulicAPI getUserid],@"client_model":phoneModel,@"client_os":phoneVersion,@"network":networkStr,@"location":locationStr};
            }
        else{
            upLoadApiInfoDic = @{@"user_id":@"",@"client_model":phoneModel,@"client_os":phoneVersion,@"network":networkStr,@"location":locationStr
                                 };

    }
    NSString *upLoadApiInfoStr = [ZFHttpTool sortBodyStr:upLoadApiInfoDic];
    
    
    [ZFHttpTool postWithURL:[NSString stringWithFormat:@"%@/user/postAppOpenRecord",SERVERIP] params:upLoadApiInfoDic bodyStr:upLoadApiInfoStr success:^(id responseObject) {
        NSLog(@"%@-%@",responseObject,responseObject[@"msg"]);
    } failure:^(NSError *error) {
        
    }];
}


@end
